package com.rabboit.web;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: LI-CI-GAO
 * 作者: licigao
 * 日期: 2021/8/31  20:45
 * 描述:
 */
@RestController
public class TestRabbitCotroller {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("test01")
    public void test(){
        rabbitTemplate.convertAndSend("ZHI-LIAN","ZHILIAN-KEY","123456668");
    }

    @RequestMapping("test02")
    public void test2(){
        rabbitTemplate.convertAndSend("FANOUT-EX","","123456668");
    }


    @RequestMapping("test03/{key}")
    public void test3(@PathVariable("key") String key){
        rabbitTemplate.convertAndSend("TOPIC-EX",key,"88888888");
    }



    @RequestMapping("test04/{shijian}")
    public void test4(@PathVariable("shijian") String shijian){

        MessageProperties messageProperties=new MessageProperties();
        //messageProperties.setExpiration("15000");
        messageProperties.setExpiration(shijian);

        Message message=new Message((shijian+"===444444444").getBytes(),messageProperties);

        rabbitTemplate.convertAndSend("ZHI-LIAN7","ZHENG-CHANG",message);
    }


    /**
     * @author: LCG
     * @date: 2023-01-06 16:25:13
     * @description:  测试延时队列
     */
    @RequestMapping("test05/{shijian}/{message}")
    public void test5(@PathVariable("shijian") Integer shijian,@PathVariable("message") String message){
        MessageProperties messageProperties=new MessageProperties();
        messageProperties.setExpiration("15000");
        rabbitTemplate.convertAndSend("YAN-SHI-EXCHANGE","KEY-123",message,msg->{
            msg.getMessageProperties().setDelay(shijian);
            return msg;
        });
    }

}
